package com.endava.exceptions.propagation;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * The propagation of a checked exception: FileNotFoundException. The compiler
 * requires to handle or declare the exception in every method it may propagate.
 * 
 * @author Andreea
 * 
 */
public class TextExCheckedException {

	// the FileNotFoundException must be declared or handled
	static void doStuff() throws FileNotFoundException {
		System.out.println("doStuff()");
		// Java implementation: public FileInputStream(String name) throws FileNotFoundException
		FileInputStream f = new FileInputStream("file");
	}

	// the FileNotFoundException must be declared or handled
	static void badMethod() throws FileNotFoundException {
		System.out.println("badMethod()");
		doStuff();
	}

	// the FileNotFoundException must be declared or handled
	public static void main(String[] args) {
		try {
			System.out.println("main()");
			badMethod();
		} catch (FileNotFoundException e) {
			System.out.println("main: File not found.");
		}
	}

}
